package com.ly.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ly.entity.JoinTeam;
import com.ly.pojo.dto.JoinTeamDTO;
import com.ly.pojo.vo.JoinTeamVO;
import com.ly.service.JoinTeamService;
import com.ly.utils.ExcludeToken;
import com.ly.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : 黑渊白花
 * @ClassName JoinTeamController
 * @date : 2025/2/10 21:47
 * @Description
 */
@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/joinTeam")
@Slf4j
public class JoinTeamController {
    @Autowired
    private JoinTeamService joinTeamService;

    @GetMapping("/Allpage")
    public Object Allpage( JoinTeamDTO joinTeamDTO){
        IPage<JoinTeamVO> allPage = joinTeamService.getAllPage(joinTeamDTO);
        return Result.success(allPage);
    }

    @GetMapping("/page")
    public Object page( JoinTeamDTO joinTeamDTO){
        IPage<JoinTeamVO> allPage = joinTeamService.getPage(joinTeamDTO);
        return Result.success(allPage);
    }

    //审核通过的同时加入进成员
    @PutMapping("/audit")
    public Result audit(@RequestBody JoinTeam joinTeam){
        if(joinTeam.getStatus()==2){
            joinTeamService.auditJoinTeam(joinTeam);
        }
        if(joinTeam.getStatus()==1){
            joinTeamService.updateById(joinTeam);
        }

        return Result.success("审核通过");
    }

    @PutMapping("/update")
    public Result update(@RequestBody JoinTeam joinTeam){
        joinTeamService.updateById(joinTeam);
        return Result.success();
    }


    @PostMapping("/save")
    public Result save(@RequestBody JoinTeam joinTeam){
        joinTeamService.save(joinTeam);
        return Result.success();
    }

    @GetMapping("/getJoinTNumByTeamId/{teamId}")
    @ExcludeToken
    public Result getJoinTNumByTeamId(@PathVariable Integer teamId){
        long count = joinTeamService.getJoinTNumByTeamId(teamId);
        return Result.success(count);
    }

    @PutMapping("/applyTeam")
    public Result applyTeam(@RequestBody JoinTeam joinTeam){
        return  joinTeamService.applyTeam(joinTeam);
    }

    @PutMapping("/isApplyTeam")
    @ExcludeToken
    public Result isApplyTeam(@RequestBody JoinTeam joinTeam){
        Boolean b = joinTeamService.isapplyTeam(joinTeam);
        if(b==false){
            return Result.success(0);
        }
        return Result.success(1);
    }




}
